namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Globalization;
    using System.Threading;
    using System.Web.Mvc;
    using System.Web.Routing;
    using SimpleWebServices;
    using SimpleWebServices.Web.Routing;
    using Xunit;

    public sealed class RootControllerFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<RootController>()
                .DerivesFrom<Controller>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IRegisterRoutes>()
                .IsDecoratedWith<InternalServerErrorAttribute>()
                .Allow("GET, HEAD, OPTIONS")
                .IsDecoratedWith<CacheControlAttribute>()
                .IsDecoratedWith<ContentLanguageAttribute>()
                .IsDecoratedWith<ContentLocationAttribute>()
                .IsDecoratedWith<ContentMD5Attribute>()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new RootController());
        }

        [Fact]
        public void op_Register_RouteCollection()
        {
            RouteCollection routes = new RouteCollection();

            (new RootController() as IRegisterRoutes).Register(routes);

            Assert.Equal<int>(2, routes.Count);

            Assert.Equal<string>(string.Empty, (routes[0] as Route).Url);
            Assert.Equal<string>(string.Empty, (routes[1] as Route).Url);
        }

        [Fact]
        public void op_Register_RouteCollectionNull()
        {
            Assert.Throws<ArgumentNullException>(() => (new RootController() as IRegisterRoutes).Register(null as RouteCollection));
        }

        [Fact]
        public void op_SeeOther()
        {
            CultureInfo culture = Thread.CurrentThread.CurrentUICulture;

            try
            {
                Assert.IsAssignableFrom<SeeOtherResult>(new RootController().SeeOther());
            }
            finally
            {
                Thread.CurrentThread.CurrentUICulture = culture;
            }
        }
    }
}